package com.wiloon.androidx.network;

import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.util.Log;

import org.apache.log4j.Logger;

public class TrafficService extends Service {
    private static Logger logger = Logger.getLogger(TrafficService.class);
    private static final String tag = "local service";
    private Handler mHandler;

    static {
        logger.debug("traffic obj.");
    }

    @Override
    public IBinder onBind(Intent arg0) {
        Log.d(tag, "onBind");
        return binder;
    }

    @Override
    public boolean onUnbind(Intent arg0) {
        Log.d(tag, "on un bind");
        return true;
    }

    @Override
    public void onCreate() {
        logger.debug("onCreate");

        super.onCreate();

//        mHandler = new Handler() {
//            @Override
//            public void handleMessage(Message msg) {
//                super.handleMessage(msg);
//                if (msg.what == 1) {
//                    // System.out.println((float) (msg.arg1 / 1024) + "kb/s");
//                    logger.debug((float) (msg.arg1 / (1024 * 3))
//                            + "k/s");
//                    //view.tv_show.setText((float) (msg.arg1 / (1024 * 3))
//                    //  + "k/s");
//
//                }
//            }
//        };
    }

    @Override
    public void onStart(Intent intent, int startId) {
        logger.debug("onStart");
        super.onStart(intent, startId);
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        Log.d(tag, "onStart");
        return START_STICKY;
    }

    @Override
    public void onDestroy() {
        Log.d(tag, "onDestroy");
        super.onDestroy();
    }

    private final IBinder binder = new LocalBinder();

    public class LocalBinder extends Binder {
        public TrafficService getService() {
            return TrafficService.this;
        }
    }

    public String getTag() {
        return tag;
    }
}
